package com.c1802.action;

import com.c1802.dao.CommentDao;
import com.c1802.dao.Impl.CommentDaiImpl;
import com.c1802.dao.Impl.LeaveDaoImpl;
import com.c1802.dao.Impl.UserDaoImpl;
import com.c1802.dao.LeaveDao;
import com.c1802.dao.UserDao;
import com.c1802.entity.Comment_hf;
import com.c1802.entity.Leave_Word;
import com.c1802.entity.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class UserAction extends ActionSupport {
    private String uname;
    private  String upass;


    public String getUname() {
        return uname;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }

    public String getUpass() {
        return upass;
    }

    public void setUpass(String upass) {
        this.upass = upass;
    }

    @Override
    public String execute() throws SQLException {
        HttpServletRequest request= ServletActionContext.getRequest();
        UserDao dao=new UserDaoImpl();
        User user= null;
        user = dao.login(uname,upass);
        if (user==null)
        {
            return "error";
        }else{
            LeaveDao dao1=new LeaveDaoImpl();
            CommentDao dao2=new CommentDaiImpl();
            List<Leave_Word> list=new ArrayList<Leave_Word>();
            list=dao1.Leavefind();
            System.out.println(list);
            List<Comment_hf> comm=dao2.find();
            request.getSession().setAttribute("user",user);
            request.getSession().setAttribute("comm",comm);
            request.getSession().setAttribute("Leavelist",list);
            System.out.println(user);
            return "success";
        }
    }
}
